package com.sgb.merchant.view.activity;

import android.content.Intent;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.GridLayoutManager;

import com.alibaba.android.arouter.facade.annotation.Autowired;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.config.PictureConfig;
import com.luck.picture.lib.entity.LocalMedia;
import com.sgb.link.entity.AMapAddressEntity;
import com.sgb.link.entity.merchant.EditIndustryInfoEntity;
import com.sgb.link.entity.merchant.IndustryCategoryEntity;
import com.sgb.link.entity.merchant.PublishIndustryEntity;
import com.sgb.link.router.PathMerchant;
import com.sgb.link.router.PathUser;
import com.sgb.link.service.MapService;
import com.sgb.link.utils.EntityConversion;
import com.sgb.merchant.R;
import com.sgb.merchant.databinding.MerchantActivityPublishParksBinding;
import com.sgb.merchant.view.adapter.PicImageAdapter;
import com.sgb.merchant.viewmodel.PublishIndustryViewModel;
import com.sgb.merchant.widget.MultipleSelectTypePopWindow;
import com.swgk.core.base.model.entity.RouterKey;
import com.swgk.core.common.base.BaseActivity;
import com.swgk.core.customview.ItemInputTextView;
import com.swgk.core.dialog.BasePopWindow;
import com.swgk.core.util.CheckUtils;
import com.swgk.core.util.ClickUtils;
import com.swgk.core.util.MToast;
import com.swgk.core.util.PickerHelper;
import com.zhy.view.flowlayout.FlowLayout;
import com.zhy.view.flowlayout.TagAdapter;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

/**
 * @author: 王彬臣
 * @date: 2021/10/15
 * @Description: 发布产业园区-第一页
 */
@Route(path = PathMerchant.ActivityPublishParks)
public class ActivityPublishParks extends BaseActivity<PublishIndustryViewModel, MerchantActivityPublishParksBinding> implements ItemInputTextView.OnWholeItemClickListener {
    @Autowired(name = RouterKey.NO, desc = "产业园区no")
    String no;

    @Autowired(name = RouterKey.BOOLEAN, desc = "是否编辑")
    boolean isEdit;

    @Autowired(name = PathUser.AMapDialog)
    MapService mapService;

    @Autowired(name = RouterKey.BOOLEAN2, desc = "是否来着我的页面")
    boolean isSelf = false;

    PicImageAdapter logoAdapter, imageAdapter;
    //图片上传
    private List<LocalMedia> selectList = new ArrayList<>();
    private List<String> urls = new ArrayList<>();
    private List<File> fileList = new ArrayList<>();

    private List<LocalMedia> logoSelectList = new ArrayList<>();
    private List<String> logoUrls = new ArrayList<>();
    private List<File> logoFileList = new ArrayList<>();

    private String name, address, leve, types, areas, average,
            supply, goodsAverage, goodsSupply, group,
            device, discounts, linkName, linkPhone, desInfo;

    ArrayList<PublishIndustryEntity.ParkLabelsBean> mTagList = new ArrayList<>();
    PublishIndustryEntity mEntity;
    boolean logoType = true;
    private TagAdapter tagAdapter;
    MultipleSelectTypePopWindow levePop, typePop, groupPop, discountPop, devicePop;

    private OptionsPickerView levePicker, typePicker;

    @Override
    protected int layoutId() {
        return R.layout.merchant_activity_publish_parks;
    }

    @Override
    protected void createViewModel() {
        mViewModel = new ViewModelProvider(this).get(PublishIndustryViewModel.class);
    }

    @Override
    protected void init() {

        ARouter.getInstance().inject(this);
        mBinding.setOnClick(this);
        mBinding.actionBar.setOnBackClickListener(this);
        mBinding.actionBar.setMenuFunctionClick(this);
        mBinding.itvAddress.setOnWholeItemClickListener(this);
        mBinding.itvAddress.setContentTextEnd();
        mBinding.itvLeve.setOnWholeItemClickListener(this);
        mBinding.itvTypes.setOnWholeItemClickListener(this);
        mBinding.itvAreas.setInfilterType(ItemInputTextView.TYPE_NUMBER_INTEGER);
        mBinding.itvAreas.setLabelRightMargin();
        mBinding.itvAverage.setInfilterType(ItemInputTextView.TYPE_NUMBER_DECIMAL);
        mBinding.itvAverage.setCheck(10, 2, false);
        mBinding.itvAverage.setLabelRightMargin();
        mBinding.itvSupply.setInfilterType(ItemInputTextView.TYPE_NUMBER_INTEGER);
        mBinding.itvSupply.setLabelRightMargin();
        mBinding.itvGoodsAverage.setInfilterType(ItemInputTextView.TYPE_NUMBER_DECIMAL);
        mBinding.itvGoodsAverage.setCheck(10, 2, false);
        mBinding.itvGoodsAverage.setLabelRightMargin();
        mBinding.itvGoodsSupply.setInfilterType(ItemInputTextView.TYPE_NUMBER_INTEGER);
        mBinding.itvGoodsSupply.setLabelRightMargin();
        mBinding.itvGroup.setOnWholeItemClickListener(this);
        mBinding.itvDevice.setOnWholeItemClickListener(this);
        mBinding.itvDiscounts.setOnWholeItemClickListener(this);
        mBinding.itvLinkPhone.setInfilterType(ItemInputTextView.TYPE_PHONE);
        if (isEdit) {
            mBinding.actionBar.setTitle("编辑产业园区");
        }


        imageAdapter = new PicImageAdapter(this, null, null, 10);
        imageAdapter.setAddClickListener(new PicImageAdapter.addClickListener() {
            @Override
            public void add() {
                logoType = false;
            }
        });
        mBinding.recyclerView.setLayoutManager(new GridLayoutManager(this, 4));
        mBinding.recyclerView.setAdapter(imageAdapter);

        logoAdapter = new PicImageAdapter(this, null, null, 1);
        logoAdapter.setDelClickListener(new PicImageAdapter.delClickListener() {
            @Override
            public void del(int position) {
                if (isEdit && !TextUtils.isEmpty(mEntity.getParkLogo())) {
                    mEntity.setParkLogo("");
                }
            }
        });
        logoAdapter.setAddClickListener(new PicImageAdapter.addClickListener() {
            @Override
            public void add() {
                logoType = true;
            }
        });
        mBinding.rvLogo.setLayoutManager(new GridLayoutManager(this, 4));
        mBinding.rvLogo.setAdapter(logoAdapter);
        if (TextUtils.isEmpty(no)) {
            mEntity = new PublishIndustryEntity();
            mEntity.setImIndustrialParkQualificationsDTO(new PublishIndustryEntity.ImIndustrialParkQualificationsDTOBean());
            mEntity.setImIndustrialParkTrendsList(new ArrayList<>());
            mEntity.setParkImages(new ArrayList<>());
        } else {
            mViewModel.getParkInfo(no);
        }


        initPop();
        initData();
    }

    private void initData() {
        mViewModel.ldType.observe(this, data -> {

            typePicker = PickerHelper.with(this).getCommonPicker("选择园区类型", data, new OnOptionsSelectListener() {
                @Override
                public void onOptionsSelect(int options1, int options2, int options3, View v) {
                    IndustryCategoryEntity firstCategory = data.get(options1);
                    mBinding.itvTypes.setContent(firstCategory.getCategoryName());
                    mEntity.setParkTypeNo(Long.valueOf(firstCategory.getCategoryNo()));
                }
            });
            typePicker.show();
        });
        mViewModel.ldLeve.observe(this, data -> {
            levePicker = PickerHelper.with(this).getCommonPicker("选择行政等级", data, new OnOptionsSelectListener() {
                @Override
                public void onOptionsSelect(int options1, int options2, int options3, View v) {
                    IndustryCategoryEntity firstCategory = data.get(options1);
                    mBinding.itvLeve.setContent(firstCategory.getCategoryName());
                    mEntity.setAssistantSectionLevelNo(Long.valueOf(firstCategory.getCategoryNo()));
                }
            });
            levePicker.show();
        });
        mViewModel.ldDiscount.observe(this, data -> {
            discountPop.setDataList("选择办公优惠", data);
            discountPop.showPopwindowBottom(mBinding.rlRoot);
        });
        mViewModel.ldGroup.observe(this, data -> {
            groupPop.setDataList("选择产业集群", data);
            groupPop.showPopwindowBottom(mBinding.rlRoot);
        });
        mViewModel.ldDevice.observe(this, data -> {
            devicePop.setDataList("选择基础设施", data);
            devicePop.showPopwindowBottom(mBinding.rlRoot);
        });

        mViewModel.ldData.observe(this, data -> {
            EditIndustryInfoEntity.ParkInfoBean parkInfo = data.getParkInfo();
            mEntity = EntityConversion.modelA2B(data.getParkInfo(), PublishIndustryEntity.class);
            PublishIndustryEntity.ImIndustrialParkQualificationsDTOBean parkQualificationsDTOBean = new PublishIndustryEntity.ImIndustrialParkQualificationsDTOBean();
            parkQualificationsDTOBean.setBusinessScope(data.getParkQualification().getBusinessScope());
            parkQualificationsDTOBean.setCollaboratorQualifications(data.getParkQualification().getCollaboratorQualifications());
            parkQualificationsDTOBean.setLocateFee(data.getParkQualification().getLocateFee());
            parkQualificationsDTOBean.setRevenueYear(data.getParkQualification().getRevenueYear());
            parkQualificationsDTOBean.setQualificationVolume(data.getParkQualification().getQualificationVolume());
            parkQualificationsDTOBean.setNo(Long.valueOf(data.getParkQualification().getNo()));
            parkQualificationsDTOBean.setTaxTypes(data.getParkQualification().getTaxTypes());
            parkQualificationsDTOBean.setQualificationTypes(data.getParkQualification().getQualificationTypes().getConstantKey());

            mEntity.setImIndustrialParkQualificationsDTO(parkQualificationsDTOBean);
            mEntity.setImIndustrialParkTrendsList(new ArrayList<>());
            ArrayList<String> logoUrl = new ArrayList<>();
            logoUrl.add(mEntity.getParkLogo());
            logoAdapter.setNetImgList(logoUrl);
            imageAdapter.setNetImgList(mEntity.getParkImages());
            mBinding.itvName.setContent(mEntity.getParkName());
            mBinding.itvAddress.setContent(parkInfo.getProvinceName() + parkInfo.getCityName() + parkInfo.getRegionName() + parkInfo.getAddressInfo());
            mBinding.itvLeve.setContent(parkInfo.getAssistantSectionLevelName());
            mBinding.itvTypes.setContent(parkInfo.getParkTypeName());
            mBinding.itvAreas.setContent(parkInfo.getParkArea());
            mBinding.itvGoodsAverage.setContent(parkInfo.getCommercialLandPrice());
            mBinding.itvGoodsSupply.setContent(parkInfo.getCommercialLandSupply());
            mBinding.itvAverage.setContent(parkInfo.getIndustrialLandPrice());
            mBinding.itvSupply.setContent(parkInfo.getIndustrialLandSupply());
            mBinding.itvGroup.setContent("已选择产业集群");
            mBinding.llGroupContent.setVisibility(View.VISIBLE);
            mBinding.tvContent.setText(parkInfo.getClusterNames().replace(",", "/"));
            mBinding.itvGroup.setDeliverLineVG(false);
            mBinding.itvDevice.setContent("已选择基础设施");
            mBinding.llDeviceContent.setVisibility(View.VISIBLE);
            mBinding.tvDeviceContent.setText(parkInfo.getInfrastructureNames().replace(",", "/"));
            mBinding.itvDevice.setDeliverLineVG(false);
            mBinding.itvDiscounts.setContent("已选择办公优惠");
            mBinding.llDiscountsContent.setVisibility(View.VISIBLE);
            mBinding.tvDiscountsContent.setText(parkInfo.getOfficeNames().replace(",", "/"));
            mBinding.itvDiscounts.setDeliverLineVG(false);
            mBinding.itvLinkPhone.setContent(parkInfo.getLinkPhone());
            mBinding.itvLinkName.setContent(parkInfo.getLinkName());
            mBinding.etDesc.setEditContent(parkInfo.getParkInfo());

            List<PublishIndustryEntity.ParkLabelsBean> mTags;
            mTagList = (ArrayList<PublishIndustryEntity.ParkLabelsBean>) mEntity.getParkLabels();
            if (mTagList.size() > 0) {
                mBinding.tvTagContent.setHint("");

            }
            if (parkInfo.getParkLabels().size() > 3) {
                mTags = mTagList.subList(0, 3);
                mBinding.tvTagContent.setText("...");
            } else {
                mTags = mTagList;
            }

            tagAdapter = new TagAdapter<PublishIndustryEntity.ParkLabelsBean>(mTags) {
                @Override
                public View getView(FlowLayout parent, int position, PublishIndustryEntity.ParkLabelsBean parkLabelsBean) {
                    final LayoutInflater mInflater = LayoutInflater.from(ActivityPublishParks.this);
                    LinearLayout layout = (LinearLayout) mInflater.inflate(R.layout.merchant_item_edit_facility, mBinding.flTag, false);
                    TextView tvTag = layout.findViewById(R.id.tv_info);
                    tvTag.setText(parkLabelsBean.getLabelName());
                    return layout;
                }
            };
            mBinding.flTag.setAdapter(tagAdapter);

        });
    }

    public void initPop() {
        groupPop = new MultipleSelectTypePopWindow(this);
        groupPop.setSingleSelect(false);
        groupPop.setBgView(mBinding.bgPopGrayLayout);
        groupPop.setOnResultCallBack(new BasePopWindow.OnResultCallBack() {
            @Override
            public void result(Object result) {
                List<IndustryCategoryEntity> mSelectList = (List<IndustryCategoryEntity>) result;
                List<String> mNo = new ArrayList<>();
                if (mSelectList != null && mSelectList.size() > 0) {
                    mBinding.itvGroup.setContent("已选择产业集群");
                    mBinding.llGroupContent.setVisibility(View.VISIBLE);
                    StringBuffer strBuffer = new StringBuffer();
                    for (int i = 0; i < mSelectList.size(); i++) {
                        IndustryCategoryEntity mData = mSelectList.get(i);
                        strBuffer.append(mData.getCategoryName());
                        if (i != mSelectList.size() - 1) {
                            strBuffer.append("/");
                        }
                        mNo.add(mData.getCategoryNo());
                    }
                    String selectType = strBuffer.toString();
                    mBinding.tvContent.setText(selectType);
                    mBinding.itvGroup.setDeliverLineVG(false);
                    mEntity.setClusterNos(mNo);
                } else {
                    mBinding.itvGroup.setDeliverLineVG(true);
                    mBinding.itvGroup.setContent("");
                    mBinding.llGroupContent.setVisibility(View.GONE);
                }

            }
        });
        devicePop = new MultipleSelectTypePopWindow(this);
        devicePop.setSingleSelect(false);
        devicePop.setBgView(mBinding.bgPopGrayLayout);
        devicePop.setOnResultCallBack(new BasePopWindow.OnResultCallBack() {
            @Override
            public void result(Object result) {
                List<IndustryCategoryEntity> mSelectList = (List<IndustryCategoryEntity>) result;
                if (mSelectList != null && mSelectList.size() > 0) {
                    mBinding.itvDevice.setContent("已选择基础设施");
                    mBinding.llDeviceContent.setVisibility(View.VISIBLE);
                    StringBuffer strBuffer = new StringBuffer();
                    StringBuffer strNo = new StringBuffer();
                    for (int i = 0; i < mSelectList.size(); i++) {
                        IndustryCategoryEntity mData = mSelectList.get(i);
                        strBuffer.append(mData.getCategoryName());
                        strNo.append(mData.getCategoryNo());
                        if (i != mSelectList.size() - 1) {
                            strBuffer.append("/");
                            strNo.append(",");
                        }

                    }
                    String selectType = strBuffer.toString();
                    mBinding.tvDeviceContent.setText(selectType);
                    mBinding.itvDevice.setDeliverLineVG(false);
                    mEntity.setInfrastructureNo(strNo.toString());
                } else {
                    mBinding.itvDevice.setContent("");
                    mBinding.itvDevice.setDeliverLineVG(true);
                    mBinding.llDeviceContent.setVisibility(View.GONE);
                }

            }
        });
        discountPop = new MultipleSelectTypePopWindow(this);
        discountPop.setSingleSelect(false);
        discountPop.setBgView(mBinding.bgPopGrayLayout);
        discountPop.setOnResultCallBack(new BasePopWindow.OnResultCallBack() {
            @Override
            public void result(Object result) {
                List<IndustryCategoryEntity> mSelectList = (List<IndustryCategoryEntity>) result;
                if (mSelectList != null && mSelectList.size() > 0) {
                    mBinding.itvDiscounts.setContent("已选择办公优惠");
                    mBinding.llDiscountsContent.setVisibility(View.VISIBLE);
                    StringBuffer strBuffer = new StringBuffer();
                    StringBuffer strNo = new StringBuffer();
                    for (int i = 0; i < mSelectList.size(); i++) {
                        IndustryCategoryEntity mData = mSelectList.get(i);
                        strBuffer.append(mData.getCategoryName());
                        strNo.append(mData.getCategoryNo());
                        if (i != mSelectList.size() - 1) {
                            strBuffer.append("/");
                            strNo.append(",");
                        }

                    }
                    String selectType = strBuffer.toString();
                    mBinding.tvDiscountsContent.setText(selectType);
                    mBinding.itvDiscounts.setDeliverLineVG(false);
                    mEntity.setOfficeNo(strNo.toString());
                } else {
                    mBinding.itvDiscounts.setContent("");
                    mBinding.itvDiscounts.setDeliverLineVG(true);
                    mBinding.llDiscountsContent.setVisibility(View.GONE);
                }

            }
        });
    }

    public void getEditContent() {
        name = mBinding.itvName.getContent();
        address = mBinding.itvAddress.getContent();
        types = mBinding.itvTypes.getContent();
        areas = mBinding.itvAreas.getContent();
        average = mBinding.itvAverage.getContent();
        supply = mBinding.itvSupply.getContent();
        leve = mBinding.itvLeve.getContent();
        goodsSupply = mBinding.itvGoodsSupply.getContent();
        goodsAverage = mBinding.itvGoodsAverage.getContent();
        group = mBinding.itvGroup.getContent();
        device = mBinding.itvDevice.getContent();
        discounts = mBinding.itvDiscounts.getContent();
        linkName = mBinding.itvLinkName.getContent();
        linkPhone = mBinding.itvLinkPhone.getContent();
        desInfo = mBinding.etDesc.getEditContent();

    }


    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.iv_back_red) {
            finish();
        } else if (id == R.id.tv_next) {
            if (ClickUtils.isDoubleClick()) {
                return;
            }
            getEditContent();
            if (logoAdapter.getUrls().size() == 0) {
                MToast.showToast(this, "请上传园区LOGO！");
                return;
            }
            if (TextUtils.isEmpty(name)) {
                MToast.showToast(this, "请输入园区名称！");
                return;
            }
            if (TextUtils.isEmpty(address)) {
                MToast.showToast(this, "请点击图标定位园区地址！");
                return;
            }
            if (TextUtils.isEmpty(leve)) {
                MToast.showToast(this, "请选择行政等级！");
                return;
            }
            if (TextUtils.isEmpty(types)) {
                MToast.showToast(this, "请选择园区类型！");
                return;
            }
            if (TextUtils.isEmpty(areas)) {
                MToast.showToast(this, "请输入园区面积！");
                return;
            }
            if (TextUtils.isEmpty(average)) {
                MToast.showToast(this, "请输入工业土地均价！");
                return;
            }

            if (TextUtils.isEmpty(supply)) {
                MToast.showToast(this, "请输入工业土地供应量！");
                return;
            }
            if (TextUtils.isEmpty(goodsAverage)) {
                MToast.showToast(this, "请输入商办土地均价！");
                return;
            }
            if (TextUtils.isEmpty(goodsSupply)) {
                MToast.showToast(this, "请输入商办土地供应量！");
                return;
            }
            if (TextUtils.isEmpty(group)) {
                MToast.showToast(this, "请选择产业集群！");
                return;
            }
            if (TextUtils.isEmpty(device)) {
                MToast.showToast(this, "请选择基础设施！");
                return;
            }
            if (TextUtils.isEmpty(discounts)) {
                MToast.showToast(this, "请选择办公优惠！");
                return;
            }
            if (mTagList.size() == 0) {
                MToast.showToast(this, "请输入惠及配套！");
                return;
            }

            if (TextUtils.isEmpty(linkName)) {
                MToast.showToast(this, "请输入联系人！");
                return;
            }

            if (TextUtils.isEmpty(linkPhone)) {
                MToast.showToast(this, "请输入联系电话！");
                return;
            } else if (!CheckUtils.isMobileForService(linkPhone)) {
                MToast.showToast(this, "请输入正确的电话格式！");
                return;
            }
            if (TextUtils.isEmpty(desInfo)) {
                MToast.showToast(this, "请输入园区简介！");
                return;
            }
            mEntity.setParkName(name);
            mEntity.setParkArea(Integer.valueOf(areas));
            mEntity.setIndustrialLandPrice(Double.valueOf(average));
            mEntity.setIndustrialLandSupply(Integer.valueOf(supply));
            mEntity.setCommercialLandPrice(Double.valueOf(goodsAverage));
            mEntity.setCommercialLandSupply(Integer.valueOf(goodsSupply));
            mEntity.setLinkName(linkName);
            mEntity.setLinkPhone(linkPhone);
            mEntity.setParkInfo(desInfo);
            ARouter.getInstance().build(PathMerchant.SelfDynamicActivity).withSerializable(RouterKey.DATA, mEntity).withBoolean(RouterKey.BOOLEAN, isSelf).
                    withStringArrayList(RouterKey.DATA1, logoAdapter.getUrls()).withStringArrayList(RouterKey.DATA2, imageAdapter.getUrls()).navigation(this, 1000);
        } else if (id == R.id.rl_tag) {
            ARouter.getInstance().build(PathMerchant.SelectFacilityCityActivity).withSerializable(RouterKey.DATA, mTagList).navigation(this, 1100);
        }
    }

    @Override
    public void OnWholeItemClick(View view) {
        int id = view.getId();
        if (id == R.id.itv_types) {
            if (mViewModel.ldType.getValue() == null) {
                mViewModel.getType();
            } else {
                typePicker.show();
            }
        } else if (id == R.id.itv_leve) {
            if (mViewModel.ldLeve.getValue() == null) {
                mViewModel.getLevel();
            } else {
                levePicker.show();
            }
        } else if (id == R.id.itv_group) {
            if (mViewModel.ldGroup.getValue() == null) {
                mViewModel.getGroup();
            } else {
                groupPop.showPopwindowBottom(mBinding.rlRoot);
            }
        } else if (id == R.id.itv_device) {
            if (mViewModel.ldDevice.getValue() == null) {
                mViewModel.getDevice();
            } else {
                devicePop.showPopwindowBottom(mBinding.rlRoot);
            }
        } else if (id == R.id.itv_discounts) {
            if (mViewModel.ldDiscount.getValue() == null) {
                mViewModel.getDiscount();
            } else {
                discountPop.showPopwindowBottom(mBinding.rlRoot);
            }
        } else if (id == R.id.itv_address) {
            if (mapService != null)
                mapService.launchMap(this);
        }


    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            if (requestCode == PictureConfig.CHOOSE_REQUEST) {// 图片结果回调
                // 图片、视频、音频选择结果回调
                if (logoType) {
                    logoSelectList = PictureSelector.obtainMultipleResult(data);
                    logoFileList.clear();
                    logoUrls.clear();
                    for (LocalMedia localMedia : logoSelectList) {
                        File file = new File(localMedia.getCompressPath());
                        logoFileList.add(file);
                        logoUrls.add(localMedia.getCompressPath());
                    }
                    logoAdapter.setDatas(logoSelectList, logoUrls);
                    logoAdapter.setFileList(logoFileList);
                } else {
                    selectList = PictureSelector.obtainMultipleResult(data);
                    fileList.clear();
                    urls.clear();
                    for (LocalMedia localMedia : selectList) {
                        File file = new File(localMedia.getCompressPath());
                        fileList.add(file);
                        urls.add(localMedia.getCompressPath());
                    }
                    imageAdapter.setDatas(selectList, urls);
                    imageAdapter.setFileList(fileList);
                }
            } else if (requestCode == 2500) {
                AMapAddressEntity entity = mViewModel.get(data);
                if (entity == null) return;
                mBinding.itvAddress.setContent(entity.getProvince() + entity.getCity() + entity.getDistrict() + entity.getSnippet());
                mEntity.setAddressInfo(entity.getSnippet());
                mEntity.setAddressLat(entity.getLatitude());
                mEntity.setAddressLng(entity.getLongitude());
                mEntity.setProvinceCode(Integer.valueOf(entity.getProvinceNo()));
                mEntity.setCityCode(Integer.valueOf(entity.getCityNo()));
                mEntity.setRegionCode(Integer.valueOf(entity.getDistrictNo()));
            } else if (requestCode == 1000) {
                if (data == null) {
                    finish();
                }
                if (data != null && data.getSerializableExtra("info") != null) {
                    mEntity = (PublishIndustryEntity) data.getSerializableExtra("info");
                }
            } else if (requestCode == 1100) {
                mTagList.clear();
                ArrayList<PublishIndustryEntity.ParkLabelsBean> mTag = (ArrayList<PublishIndustryEntity.ParkLabelsBean>) data.getSerializableExtra("tagList");
                if (mTag != null) {
                    mTagList.addAll(mTag);
                    mBinding.tvTagContent.setHint("");

                    List<PublishIndustryEntity.ParkLabelsBean> mTags;
                    if (mTag.size() > 3) {
                        mTags = mTagList.subList(0, 3);
                        mBinding.tvTagContent.setText("...");
                    } else {
                        mTags = mTagList;
                        mBinding.tvTagContent.setText("");
                    }
                    tagAdapter = new TagAdapter<PublishIndustryEntity.ParkLabelsBean>(mTags) {
                        @Override
                        public View getView(FlowLayout parent, int position, PublishIndustryEntity.ParkLabelsBean parkLabelsBean) {
                            final LayoutInflater mInflater = LayoutInflater.from(ActivityPublishParks.this);
                            LinearLayout layout = (LinearLayout) mInflater.inflate(R.layout.merchant_item_edit_facility, mBinding.flTag, false);
                            TextView tvTag = layout.findViewById(R.id.tv_info);
                            tvTag.setText(parkLabelsBean.getLabelName());
                            return layout;
                        }
                    };
                    mBinding.flTag.setAdapter(tagAdapter);
                }
                mEntity.setParkLabels(mTagList);
                tagAdapter.notifyDataChanged();


            }
        }
        if (requestCode == 255) {
            if (data == null) {
                return;
            }
        }
    }
}
